<template>
  <slot v-if="handleType === 'create' || handleType=== 'edit' "></slot>
  <slot v-if="handleType === 'view' " name="view" :now-value="{nowValue}" :old-value="{oldValue}" :is-diff="{isDiff}">
    <el-tooltip :disabled="!isDiff" :content="`修改前为：${oldValue}`">
      <div :class="{diffColor: isDiff}">
        {{nowValue}}
      </div>
    </el-tooltip>
  </slot>
</template>
<script setup>
import { computed } from 'vue'

const {handleType,nowValue,oldValue} = defineProps(['handleType','nowValue','oldValue'])
console.log("1",nowValue)
console.log("2",oldValue)
const isDiff = computed(()=>{

  if(oldValue === undefined || oldValue === ''){
    return false;
  }
  //判断数组
  if(nowValue instanceof  Array && oldValue instanceof  Array){
    return nowValue.length !== oldValue.length
  }
  return nowValue !== oldValue
})
</script>

<style scoped>
.diffColor{
  background-color: red;
}
</style>
